package com.xxx.video.main.adapters;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.xxx.video.R;
import com.xxx.video.commen.adapters.BaseRecycleViewAdapter;
import com.xxx.video.commen.adapters.BaseViewHolder;
import com.xxx.video.commen.utils.StringUtils;
import com.xxx.video.main.beans.SystemMessageBean;

import butterknife.BindView;

public class SystemMessageListAdapter extends BaseRecycleViewAdapter<SystemMessageBean.PageBean.ListBean, SystemMessageListAdapter.MyHolder> {

    public SystemMessageListAdapter(@NonNull Context context) {
        super(context);
    }

    @Override
    public MyHolder onCreateDefaultViewHolder(View view, int viewType) {
        return new MyHolder(view);
    }

    @Override
    public int getItemLayout(int viewType) {
        return R.layout.item_system_message_list;
    }

    @Override
    public boolean isSetBaseItemViewClickListener() {
        return false;
    }

    class MyHolder extends BaseViewHolder {

        @BindView(R.id.tv_item_system_message_list_desc)
        TextView tvItemSystemMessageListDesc;
        @BindView(R.id.tv_item_system_message_list_date)
        TextView tvItemSystemMessageListDate;
        @BindView(R.id.tv_item_system_message_list_unread)
        View tvItemSystemMessageListUnread;
        @BindView(R.id.cl_item_system_message_list)
        ConstraintLayout clItemSystemMessageList;


        public MyHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void setData2View(int position) {
            SystemMessageBean.PageBean.ListBean listBean = getItem(position);
            /*
             * content
             */
            tvItemSystemMessageListDesc.setText(StringUtils.getInstance().getNotEmptyMsg(listBean.fContent));
            /*
             * time
             */
            tvItemSystemMessageListDate.setText(StringUtils.getInstance().getNotEmptyMsg(listBean.fCreateTime));
            tvItemSystemMessageListUnread.setVisibility(View.GONE);
            if (listBean.fStatus == 0) {
                tvItemSystemMessageListUnread.setVisibility(View.VISIBLE);
            }
            clItemSystemMessageList.setOnClickListener(v -> {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(listBean, position, 0);
                    listBean.fStatus = 1;
                    notifyDataSetChanged();
                }
            });
        }
    }
}
